/**
 * Created by ayu on 2017/6/9.
 */
let express = require ('express');
let router = express.Router ();
let verify = require ('../utils/Notify').verify;
const rawDataController = require ('../controllers/RawDataController');
/**
 * 验证 合法性
 * @param sign
 * @param cinema_code
 */
router.use (function ( req, res, next )
{
    
    let data =  req.body;
    // data = eval('('+data+')');
    // console.log(data);
    let [
            cinemaCode = '',
            sign       = 'W0RL1z5rlm7swIItWykgUSuIULsWbrzgmLdj2fofCu3BnQI99jcBQvL02uZ+CgjGe0w9xYnatKGF4Lkngr0ciymxWXGGjKgMT1dHYEYTN1DyTkrUfwN6LYTHjFhUUaH/BnooN4CHOCQ6N+QPPFwjihleQ0bqKfU09NLUXJUTg24='
        ]              =
            [
                data.cinema_code,
                data.sign
            ];
    if (verify (sign, 'cinema_code=' + cinemaCode))
    {
        next ();
    }
    else
    {
        res.json ({
            status : 'error',
            message: '秘钥校验失败'
        });
    }
});
router.post ('/add' ,rawDataController.saveRawData);
module.exports = router;